import { shallowRef } from 'vue'

import { catchFn } from '@/libs/common'
import { getGroupDetail } from './api'

const detail = shallowRef<T_GroupDetail>()

export { detail }

/**
 * 更新群信息
 * @param id 群ID
 */
const update = (id: string) =>
  catchFn(async () => {
    const { data } = await getGroupDetail(id)

    detail.value = data
  })

/**
 * 还原状态
 */
const clear = () => (detail.value = undefined)

export { update, clear }
